module Tests where

import Evaluator2
import GameLoop
import Builder

import Control.Monad


main = do
  run_all_feature_tests -- этот только считает, сверка не производится
  run_all_integral_tests -- этот автоматически сверяет

-- Тесты кишек эвалуатора

tst3 = do
  modify_prop 10 (\c -> Right $ CS 0 (FA Zero []))
  modify_opp 20 (\c -> Right $ CS 100 (FA Succ [FA Zero []]))
  modify_prop 10 (\c -> if vitality c == 0 then Left "it's zero" else Right c)
  modify_prop 20 (\c -> Right $ CS (-1) (FA Succ [FA Zero []]))

tst4 = do
  eval NormalM (FA Attack [FI 100, FI 200, FI 5000])
  eval NormalM (FA Attack [FI 100, FI 200, FI 6000])
  return ()

tests = [tst3, tst4]

run_all_feature_tests = zipWithM_ (\n t -> putStrLn $ "test " ++ show n ++ ": " ++ show (ug t init_game_state) ) [1..] tests
-- Тесты полного цикла игры

-- Тесты

run_tests :: [(IO GameState, ([(Int, CellState)], [(Int, CellState)]))]  -> IO Bool
run_tests bundles = do
  let tests = map fst bundles
      answers = map snd bundles
  tests' <- sequence tests
  let res = zipWith (\gs ans -> (changed_slots (proponent gs), changed_slots (opponent gs)) == ans)
             tests' answers
  print res
  return $ and res

-- Эту запускать
run_all_integral_tests = run_tests [(single_game_loop test_game2, game2_ans)
                                   ,(single_game_loop test_gen1, test_gen1_ans)]


-- собственно тесты


-- Пример 1 из манула
-- В результате должно быть:
-- Exception: Native.Error со стороны player 1
-- slot 0 reset to I
-- player 0's turn
-- 4={10001,I}
-- 255={9999,I}
-- (slots {10000,I} are omitted)
test_game1_player0 = [0 <$ Zero, Succ $> 0, Succ $> 0, Dbl $> 0, Inc $> 0]
test_game1_player1 = [0 <$ Inc, 0 <$ Zero, 0 <$ Dec, 0 <$ Zero, Succ $> 0]



-- Пример два из манула.
-- 0={9984,I}
-- 1={10017,16}
-- (slots {10000,I} are omitted)
test_game2 = [0 <$ Help, 0 <$ Zero, K $> 0, S $> 0, 0 <$ Succ, 0 <$ Zero, 1 <$ Zero, Succ $> 1, Dbl $> 1, Dbl $> 1, Dbl $> 1, Dbl $> 1, K $> 0, S $> 0, 0 <$ Get, K $> 0, S $> 0, 0 <$ Succ, 0 <$ Zero]

game2_ans = let p1 = [(0, CS 9984 (FA I [])), (1, CS 10017 (FI 16))]
                p2 = []
            in (p1,p2)

-- Пример 3 из манула.
-- Exception: Native.AppLimitExceeded
-- slot 0 reset to I
-- ###### turn 5
-- *** player 0's turn, with slots:
-- (slots {10000,I} are omitted)
test_game3 = [0 <$ S, 0 <$ Get, 0 <$ I, 0 <$ Zero]


-- Тесты генераторов

i = 123
k = 65373

test_gen1 = gen_number i k
test_gen1_ans = let p1 = [(i, init_slot {field = FI k} )]
                    p2 = []
                in (p1,p2)